package com.gridpower.spreadsheet.client;

// import org.timepedia.chronoscope.client.browser.Chronoscope;
// import org.timepedia.chronoscope.client.canvas.Canvas;

import java.util.ArrayList;
import java.util.Iterator;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.widgetideas.graphics.client.GWTCanvas;
import com.gridpower.spreadsheet.client.models.AppModel;
import com.gridpower.spreadsheet.client.widgets.UIUtil;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class app implements EntryPoint {


	
	private GWTCanvas _canvas;
	private Button clickMeButton;
	
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
/*
		AbsolutePanel dp = new AbsolutePanel();
		dp.setSize("300px", "300px");
		clickMeButton = new Button();
		dp.add(clickMeButton, 10, 10);
		clickMeButton.setText("Click me!");
		clickMeButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
			    _canvas.setBackgroundColor(Color.GREEN);

				//Window.alert("Hello, GWT World!");
			}
		});
		
		//Canvas canvas = Chronoscope
		
	    GWTCanvas canvas = new GWTCanvas(100,100);
	    
	    canvas.setGlobalCompositeOperation(GWTCanvas.DESTINATION_OVER);
	    canvas.setLineWidth(1);
	    canvas.setBackgroundColor(Color.SKY_BLUE);
	    canvas.setStrokeStyle(Color.GREEN);
	    
	    canvas.beginPath();
	      canvas.moveTo(1,1);
	      canvas.lineTo(1,50);
	      canvas.lineTo(50,50);
	      canvas.lineTo(50, 1);
	    canvas.closePath();
	    canvas.stroke();
	    
	    canvas.setStrokeStyle(Color.RED);
	    canvas.beginPath();
		    canvas.moveTo(1,1);
		    canvas.lineTo(1,100);
		    canvas.lineTo(100,100);
		    canvas.lineTo(100, 1);
	    canvas.closePath();
	    canvas.stroke();
	    _canvas = canvas;
	    
	    dp.add(canvas, 100, 100);
	   
	    canvas = new GWTCanvas(150,150);
	    canvas.setBackgroundColor(GWTCanvas.TRANSPARENT);
	    //canvas.setGlobalAlpha(0.3);// useless
	    //canvas.setGlobalCompositeOperation(GWTCanvas.DESTINATION_OVER);
	    canvas.setLineWidth(1);
	    canvas.setStrokeStyle(Color.BLUE);
	    canvas.setFillStyle(Color.GREY);
	    canvas.beginPath();
	      canvas.moveTo(25,25);
	      canvas.lineTo(25,150);
	      canvas.lineTo(150,150);
	      canvas.lineTo(150, 25);
	      canvas.closePath();
	    canvas.stroke();
	    
	    // set style
	    DOM.setStyleAttribute(canvas.getElement(), "filter",  "Alpha(opacity=" + "50" + ")");
	    dp.add(canvas, 125,125);
	    
	    
	    
	    canvas = new GWTCanvas(200, 200);
	    canvas.resize(400, 400);
		canvas.setFillStyle(new Color(200, 0, 0));
		canvas.fillRect(10, 10, 55, 50);
		canvas.setGlobalAlpha(0.5f);
		canvas.setFillStyle(new Color(0, 200, 0));
		canvas.fillRect(30, 30, 55, 50);

		canvas.setGlobalAlpha(1);
		canvas.setLineWidth(1);
		canvas.setStrokeStyle(Color.GREEN);

		canvas.setFillStyle(new Color(255, 0, 0));

		canvas.beginPath();
		canvas.moveTo(30, 30);
		canvas.lineTo(150, 150);
		// was: canvas.quadraticCurveTo(60, 70, 70, 150); which is wrong.
		canvas.cubicCurveTo(60, 70, 60, 70, 70, 150); // <- this is right formula for the image on the right ->
		canvas.lineTo(30, 30);
		canvas.fill();

		canvas.setStrokeStyle(Color.BLACK);
		canvas.beginPath();
		canvas.arc(75, 75, 50, 0, (float) (Math.PI * 2), true);
		canvas.moveTo(110, 75);
		canvas.arc(75, 75, 35, 0, (float) Math.PI, false);
		canvas.moveTo(65, 65);
		canvas.arc(60, 65, 5, 0, (float) (Math.PI * 2), true); 
		canvas.moveTo(95, 65);
		canvas.arc(90, 65, 5, 0, (float) (Math.PI * 2), true); 
		canvas.stroke();

		canvas.setLineWidth(1);
		canvas.setStrokeStyle(Color.GREEN);

		canvas.saveContext();

		canvas.setLineWidth(1);
		canvas.setStrokeStyle(Color.RED);

		canvas.translate(100, 100);
		canvas.strokeRect(0, 0, 100, 100);
		canvas.restoreContext();

		canvas.strokeRect(1, 1, 80, 80);
		
		// create a scroll panel
		ScrollPanel scrollPanel = new ScrollPanel(canvas);
		scrollPanel.setSize("100px", "100px");
		dp.add(scrollPanel, 300,300);
		rootPanel.get().add(dp);
		*/
	    RootPanel.get().add(UIUtil.getAppView().getViewHolder());
	    AppModel.getInstance().loadFile("fileName");
	    
	}
}
